package conversion.config;


import conversion.Interceptor.TokenInterceptor;
import conversion.Interceptor.RateLimitInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class WebConfig implements WebMvcConfigurer {

        @Resource
    private TokenInterceptor tokenInterceptor;

    @Resource
    private RateLimitInterceptor rateLimitInterceptor;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {

//        registry.addInterceptor(tokenInterceptor)//拦截器注册到容器中
//                .addPathPatterns("/**")  //所有请求都被拦截包括静态资源
//                .excludePathPatterns("/css/**", "/js/**", "/images/**", "/avatars/**"); //放行的请求

        // 添加RateLimitInterceptor拦截器，并设置拦截的路径
        registry.addInterceptor(rateLimitInterceptor)
                .addPathPatterns("/**")   // 拦截所有请求
                .excludePathPatterns("/js/**","/css/**","/avatars/**","/images/**","/favicon.ico");
//                .excludePathPatterns("/static/**");

    }


}
